<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: absolute;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: pink;
        }
    </style>
</head>
<body>
    <div></div>
    <script>
        // (1) 触摸元素 touchstart： 获取手指初始坐标，同时获得盒子原来的位置
        // (2) 移动手指 touchmove： 计算手指滑动的距离，并且移动盒子
        // (3) 离开手指touchend;
        var div = document.querySelector('div');
        var startX = 0; //获取手指的初始坐标
        var startY = 0;
        var x = 0;
        var y = 0;
        div.addEventListener('touchstart', function(e) {
            // 获取手指的初始坐标
            startX = e.targetTouches[0].pageX;
            startY = e.targetTouches[0].pageY;
            // 盒子距离上方和左方的距离
            x = this.offsetLeft;
            y = this.offsetTop;
        })
        div.addEventListener('touchmove', function(e) {
            var moveX = e.targetTouches[0].pageX - startX;
            var moveY = e.targetTouches[0].pageY - startY;
            this.style.left = x + moveX + 'px';
            this.style.top=  y + moveY + 'px';
            e.preventDefault();
        })
    </script>
</body>
</html>